function Bug1()

pb=projBug();
l=10;
d=l/5;
% legs
lpts0=[0 0 0].';
p=[10 10 10].';
p1=.15*[100 100 100].';
for m= 1:2
    for n= 1:4
        [lpts,lptsN]=pb.limb(pi/180*[(-1)^m*36*n -30 0 90 -130],[10 20 30]/2,'two',[ 2*(-1)^(m+1)*sin(pi*(d*n)/l) l/2-d*n 0],16,0.75);
        % lptsN: the "expanded" dense cloud of points
        % lpts: the vertices of the current joint
        lpts0=[lpts0, lptsN];
        % lpts0: the collection of all dense points (visual representation
        % of the bug)
    end
end
% body
lptsN=pb.Body([eye(3) [0 -l/2 0].'; 0 0 0 1],[eye(3) [0 l/2 0].'; 0 0 0 1],1,2,2);
lpts0=[lpts0, lptsN];
lptsN=pb.Body([rx(pi/8) [0 0 0].'; 0 0 0 1],[eye(3) [0 l*2 0].'; 0 0 0 1],.5,2,2);
lpts0=[lpts0, lptsN];
lptsN=pb.Body([rx(7*pi/8) [0 -3*l/8 0].'; 0 0 0 1],[eye(3) [0 -3*l/4 0].'; 0 0 0 1],.75,4,1);
lpts0=[lpts0, lptsN];
q=rz(5*pi/4)*p;
% viewer 3d
pb.viewer(lpts0,1);
pb.vsh(lpts0,2,q);
% % viewer 2d
ge(:,:,1)=[[-0.7071,0.7071,0;0.5,0.5,0.7071;0.5,0.50,-0.7071] , p1; 0,0,0,1];
% ge(:,:,1)=[[rz(0)] , [0 0 10].'; 0,0,0,1];
    k=16;
for m= 1:k-1
    ge(:,:,m+1)=adjoint([rz(2*pi/k*m),[ 0 0 0 ].';0 0 0 1],ge(:,:,1));
end

pb.proj(lpts0,k,ge);

end
% helper functions
function re=rx(alpha)
re=[1 0 0; 0 cos(alpha) -sin(alpha) ; 0 sin(alpha) cos(alpha)];
end
function re=ry(alpha)
re=[cos(alpha) 0 sin(alpha); 0 1 0  ; -sin(alpha) 0 cos(alpha)];
end
function re=rz(alpha1)
re=[ cos(alpha1) -sin(alpha1) 0; sin(alpha1) cos(alpha1) 0; 0 0 1];
end
function h=adjoint(g0,g1)
 h=inver(g0)*g1*g0;
end
function t=inver(g)
r=(g((1:3),(1:3)))^-1;
d=-((g((1:3),(1:3)))^-1)*g((1:3),4);
t=[r d; 0 0 0 1];
end